/**
 * 
 */
package de.gee.erep.server.services;

import java.util.ArrayList;
import java.util.Map;

import com.google.gwt.user.server.rpc.RemoteServiceServlet;

import de.gee.erep.client.calls.rpc.CitizenService;
import de.gee.erep.server.xml.CitizenParser;
import de.gee.erep.shared.entities.citizen.CitizenDetail;
import de.gee.erep.shared.entities.citizen.CitizenDetailId;
import de.gee.erep.shared.rpctypes.action.ServiceAction;
import de.gee.erep.shared.rpctypes.action.impls.GetCitizenDetails;
import de.gee.erep.shared.rpctypes.responses.ServiceResponse;
import de.gee.erep.shared.rpctypes.responses.impls.GetCitizenDetailsResponse;

/**
 * @author Matthew Gee created: 10.05.2011
 */
public class CitizenServiceImpl extends RemoteServiceServlet implements
		CitizenService {

	/***/
	private static final long serialVersionUID = 1L;

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * de.gee.erep.client.calls.rpc.CitizenService#execute(de.gee.erep.shared
	 * .rpctypes.action.ServiceAction)
	 */
	@SuppressWarnings({ "unchecked", "rawtypes" })
	@Override
	public final ServiceResponse execute(final ServiceAction action)
			throws Exception {
		ServiceResponse response = null;
		if (action instanceof GetCitizenDetails) {
			GetCitizenDetails getDetails = (GetCitizenDetails) action;
			ArrayList<CitizenDetail> details = new ArrayList<CitizenDetail>();
			Map<CitizenDetailId, CitizenDetail> map = CitizenParser.map;
			for (CitizenDetailId id : getDetails.getIds()) {
				CitizenDetail e = map.get(id);
				details.add(e);
			}
			response = new GetCitizenDetailsResponse(details);
		}
		return response;
	}
}
